package threshold;

import java.util.Arrays;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2023-02-28 22:19
 * @Version 1.0
 */
public class RemoveDuplicates {
    public int removeDuplicates(int[] nums){

        int len = nums.length;
        //i指针从前向后遍历数组，j指针从后往前遍历数组
        for (int i = 0; i <len-1 ; i++) {
            for (int j = len-1; j >i ; j--) {
                //j指针一旦找到与i指针相同的元素，就删除j指针所指向的元素
                if(nums[i]==nums[j]){
                    for(int k=j;k<len-1;k++){
                        nums[k] = nums[k+1];
                    }
                    len--;
                }
            }
        }
        return len;
    }

    public int removeDuplicates1(int[] nums){

        int len = nums.length;
        int[] temps = new int[len];
        int count = 0;
        for(int i=0;i<nums.length-1;i++){
            if(nums[i]!=nums[i+1]){
                temps[count++] = nums[i];
            }
        }
        if(nums[len-1]!=temps[count-1]){
            temps[count++] = nums[len-1];
        }
        for (int i = 0; i < count; i++) {
            System.out.print(temps[i]);
        }
        return count;

    }



    public static void main(String[] args) {
        int[] nums ={1,1,2};
        RemoveDuplicates removeDuplicates = new RemoveDuplicates();
        int len = removeDuplicates.removeDuplicates1(nums);
        System.out.println(len);

    }
}
